from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from zouxiu.items import ZouxiuItem

class ZouXiuSpider(BaseSpider):
    name = "zouxiu"
    allowed_domains = ["www.xiu.com"]
    start_urls = [
        "http://www.xiu.com/index_0.shtml"
    ]

    def parse (self, response):
        hxs = HtmlXPathSelector(response)
        temp = hxs.select('/html/body')
        #temp.select('//div[@class="bd"]').select('//a[contains(@title,"ALDO")]/@title').extract()
        #titles = temp.select('//div[@class="bd"]').select('//a/@title').extract()
        #for title in titles:
        #    print title
        titles = temp.select('.//div[@class="bd"]').select('.//a[contains(@title,"")]/span/text()').extract()
        items = []
        for title in titles:
            item = ZouxiuItem()
            item['name'] = title
            items.append(item)
        return items

